﻿Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports SIAVU.Persistencia

Namespace Dominio
    <Serializable()> _
    Public Class Plazo

#Region "Atributos privados"

        Private _Mes As Integer
        Private _Anio As Integer
        Private _FechaHastaModificacion As Date
        Private _FechaDesdeModificacion As Date
        Private _PlazoID As Long

#End Region

#Region "Propiedades"

        Public Overridable Property Mes() As Integer
            Get
                Return _Mes
            End Get
            Set(ByVal value As Integer)
                _Mes = value
            End Set
        End Property

        Public Overridable Property Anio() As Integer
            Get
                Return _Anio
            End Get
            Set(ByVal value As Integer)
                _Anio = value
            End Set
        End Property

        Public Overridable Property FechaHastaModificacion() As Date
            Get
                Return _FechaHastaModificacion
            End Get
            Set(ByVal value As Date)
                _FechaHastaModificacion = value
            End Set
        End Property

        Public Overridable Property FechaDesdeModificacion() As Date
            Get
                Return _FechaDesdeModificacion
            End Get
            Set(ByVal value As Date)
                _FechaDesdeModificacion = value
            End Set
        End Property

        Public Overridable Property PlazoID() As Long
            Get
                Return _PlazoID
            End Get
            Set(ByVal value As Long)
                _PlazoID = value
            End Set
        End Property

#End Region

#Region "Metodos"

        Public Overridable Function VerificarVigencia() As Boolean
            If (Date.Now.Date >= Me.FechaDesdeModificacion AndAlso _
            Date.Now.Date <= Me.FechaHastaModificacion) Then
                Return True
            Else
                Return False
            End If

        End Function

        Public Overridable Function getByFecha(ByVal Fecha As Date) As Plazo
            Me.Mes = Fecha.Month
            Me.Anio = Fecha.Year
            Dim oPlazoAux As Plazo
            Dim oPlazoPersistencia As New PlazoPersistencia
            oPlazoAux = oPlazoPersistencia.GetByMesAnio(Me)

            If (oPlazoAux Is Nothing) Then
                Me.FechaDesdeModificacion = Date.Now
                Me.FechaHastaModificacion = Date.Now
            Else
                Me.FechaDesdeModificacion = oPlazoAux.FechaDesdeModificacion
                Me.FechaHastaModificacion = oPlazoAux.FechaHastaModificacion
                Me.PlazoID = oPlazoAux.PlazoID
            End If

            Return Me
        End Function

        Public Shared Function getByPeriodo(ByVal Anio As Integer, ByVal Mes As Integer) As Plazo
            Try
                Dim oPlazoAux As New Plazo
                oPlazoAux.Anio = Anio
                oPlazoAux.Mes = Mes

                Dim oPlazoPersistencia As New PlazoPersistencia
                Return oPlazoPersistencia.GetByMesAnio(oPlazoAux)

            Catch ex As Exception
                Throw
            End Try
        End Function

        Public Overridable Function guardar() As Boolean
            Dim oPlazoPersistencia As New PlazoPersistencia

            Try
                oPlazoPersistencia.guardar(Me)
                Return True

            Catch ex As Exception
                Return False
            End Try
        End Function

#End Region

    End Class
End Namespace

